package com.tlgen.controller.assist;

import com.tlgen.model.Record;
import com.tlgen.model.RespBean;
import com.tlgen.model.RespPageBean;
import com.tlgen.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: tlgen
 * @Discription:
 */
@RestController
@RequestMapping("/assist/record")
public class RecordController {

    @Autowired
    RecordService recordService;

    @GetMapping("/")
    public RespPageBean getRecordByPage(@RequestParam(defaultValue = "1") Integer page,
                                          @RequestParam(defaultValue = "10") Integer size,
                                          Record record) {
        return recordService.getRecordByPage(page, size, record);
    }

    @PostMapping("/")
    public RespBean addRecord(@RequestBody Record record) {
        if (recordService.addRecord(record) == 1) {
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败!!");
    }

    @DeleteMapping("/{id}")
    public RespBean deleteRecordByEid(@PathVariable Integer id) {
        if (recordService.deleteRecordById(id) == 1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }

    @PutMapping("/")
    public RespBean updateRecord(@RequestBody Record record) {
        if (recordService.updateRecord(record) == 1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }
}
